<template>
  <div class="p-2">
    <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
      <div v-show="showSearch" class="mb-[10px]">
        <el-card shadow="hover">
          <el-form ref="queryFormRef" :model="queryParams" :inline="true">
            <el-form-item label="报告编号" prop="reportNo">
              <el-input v-model="queryParams.reportNo" placeholder="请输入报告编号" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item>
              <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
              <el-button icon="Refresh" @click="resetQuery">重置</el-button>
            </el-form-item>
          </el-form>
        </el-card>
      </div>
    </transition>

    <el-card shadow="never">
      <template #header>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <!-- <el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['system:dissent:export']">导出</el-button> -->
          </el-col>
          <right-toolbar v-model:showSearch="showSearch" :search="false" @queryTable="getList"></right-toolbar>
        </el-row>
      </template>

      <el-table v-loading="loading" border :data="dissentList">
        <el-table-column label="发起人" prop="nickName" width="200px" />
        <el-table-column label="报告编号" align="center" prop="reportNo" width="200" />
        <el-table-column label="领域" prop="field" min-width="150px" show-overflow-tooltip />
        <!-- <el-table-column label="佐证材料" prop="evidenceName" min-width="150px" /> -->
        <el-table-column label="问题说明" prop="userRemark" min-width="150px" />
        <el-table-column label="状态" align="center" prop="status" width="80px">
          <template #default="{ row }">
            <dict-tag :options="xydz_dissent_status" :value="row.status" />
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" width="130">
          <template #default="{ row }">
            <el-tooltip content="查看详情" placement="top">
              <el-button link type="primary" icon="Document" @click="showDetail(row)"></el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>

      <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
    </el-card>
    <detailDialog ref="detailDialogRef"></detailDialog>
  </div>
</template>

<script setup name="Dissent" lang="ts">
import { getDissentList } from '@/api/xydz/history/index';
import { DissentVO } from '@/api/xydz/dissent/types';
import detailDialog from './detail-dialog.vue';

const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const { xydz_dissent_status } = toRefs<any>(proxy?.useDict('xydz_dissent_status'));

const dissentList = ref<DissentVO[]>([]);
const loading = ref(true);
const showSearch = ref(true);
const total = ref(0);

const queryFormRef = ref<ElFormInstance>();
const detailDialogRef = ref<InstanceType<typeof detailDialog>>();

const state = reactive({
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    reportNo: undefined
  }
});

const { queryParams } = toRefs(state);

/** 查询异议信息列表 */
const getList = async () => {
  loading.value = true;
  const res = await getDissentList(queryParams.value);
  dissentList.value = res.rows;
  total.value = res.total;
  loading.value = false;
};

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.value.pageNum = 1;
  getList();
};

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value?.resetFields();
  handleQuery();
};

onMounted(() => {
  getList();
});

//查看详情
const showDetail = (row) => {
  detailDialogRef.value.show(row);
};
</script>
